package com.editor.smsmanager;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.CallLog;
import android.provider.MediaStore;
import android.provider.Telephony;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.editor.smsmanager.utils.MyLog;
import com.editor.smsmanager.utils.SysDataUtils;

public class ReadSmsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_read_sms);

        new Thread(){
            @Override
            public void run() {
                readSms();
                //readIncoming();
            }
        }.start();
    }

    private void readSms(){
        final String SMS_URI_INBOX = "content://sms/inbox";
        Uri uri = Uri.parse(SMS_URI_INBOX);
        Cursor cursor = getContentResolver().query(uri,null, null, null, "_id desc limit 10");

        if(cursor != null) {
            SysDataUtils.printCursor(cursor);
        }else{
            MyLog.E("SMS_URI_INBOX cursor is NULL");
        }
    }

    private void readIncoming(){
        final Uri PHONE_CALL  = Uri.parse("content://call_log/calls");

        Cursor cursor = getContentResolver().query(PHONE_CALL, null, null, null, "date desc limit 10");

        if(cursor != null) {
            SysDataUtils.printCursor(cursor);
        }else{
            MyLog.E("PHONE_CALL cursor is NULL");
        }
    }

}
